﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FootballProject.DAL.DatatAccessLib;

namespace FootballProject.BL.BusinessManagers
{
    /// <summary>
    /// Author: Ivan Shikht
    /// </summary>
    class HomeTeamManager
    {
        #region Fields
        private readonly EntitiesContext _context;
        #endregion

        #region Constructors
        public HomeTeamManager()
        {
            _context = new EntitiesContext();
        }
        #endregion

        #region Methods
        public List<HomeTeam> FindAll()
        {
            IQueryable<HomeTeam> rHomeTeam = from homeTeam in _context.HomeTeamSet
                                             select homeTeam;
            return rHomeTeam.ToList();
        }

        public List<HomeTeam> FindHomeTeamsByTeam(Team team)
        {
            IQueryable<HomeTeam> rHomeTeam = from homeTeam in _context.HomeTeamSet
                                             where homeTeam.Teams == team
                                             select homeTeam;
            return rHomeTeam.ToList();
        }

        public HomeTeam FindHomeTeamById(Guid homeTeamId)
        {
            IQueryable<HomeTeam> rHomeTeam = from homeTeam in _context.HomeTeamSet
                                             where homeTeam.HTeamID == homeTeamId
                                             select homeTeam;
            return rHomeTeam.First();
        }

        public void UpdateHomeTeam(HomeTeam homeTeam)
        {
            _context.Attach(homeTeam);
            homeTeam.SetAllModified(_context);
            _context.SaveChanges();
        }

        public void AddHomeTeam(HomeTeam homeTeam)
        {
            _context.AddToHomeTeamSet(homeTeam);
            _context.SaveChanges();
        }


        public void DeleteHomeTeam(HomeTeam homeTeam)
        {
            _context.Attach(homeTeam);
            _context.DeleteObject(homeTeam);
            _context.SaveChanges();
        }
        #endregion
    }
}
